﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Data.Odbc;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace EmailMarketingCampaign
{
    public partial class editCampaign : System.Web.UI.Page
    {
        DataSource ds = new DataSource();

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void save_Click(object sender, EventArgs e)
        {
            
            string requestQuery = "Insert into mails (subject,body,from_name,from_email,to_email) " +
                                                "Values (?,?,?,?,?)";
            MySqlCommand reqComm = new MySqlCommand();
            MySqlParameter pSubject = new MySqlParameter("@subject", OdbcType.NVarChar, 200);
            MySqlParameter pBody = new MySqlParameter("@body", OdbcType.NVarChar, 4000);
            MySqlParameter pFN = new MySqlParameter("@fromName", OdbcType.NVarChar, 200);
            MySqlParameter pFrom = new MySqlParameter("@from", OdbcType.NVarChar, 200);
            MySqlParameter pTo = new MySqlParameter("@to", OdbcType.NVarChar, 200);
            MySqlParameter[] pc = new MySqlParameter[] { pSubject, pBody, pFN, pFrom, pTo };

            //MySQL ODBC
            //OdbcCommand reqComm = new OdbcCommand();
            //OdbcParameter pSubject = new OdbcParameter("@subject", OdbcType.NVarChar, 200);
            //OdbcParameter pBody = new OdbcParameter("@body", OdbcType.NVarChar, 4000);
            //OdbcParameter pFN = new OdbcParameter("@fromName", OdbcType.NVarChar, 200);
            //OdbcParameter pFrom = new OdbcParameter("@from", OdbcType.NVarChar, 200);
            //OdbcParameter pTo = new OdbcParameter("@to", OdbcType.NVarChar, 200);
            //OdbcParameter[] pc = new OdbcParameter[] { pSubject, pBody, pFN, pFrom, pTo };

            pSubject.Value = txtSubject.Text;
            pBody.Value = txtEmailBody.Text;
            pFN.Value = txtFromName.Text;
            pFrom.Value = txtFromEmail.Text;
            pTo.Value = txtTo.Text;
            reqComm.Parameters.AddRange(pc);
            reqComm.CommandText = requestQuery;
            ds.ExecuteInsert(reqComm);            
        }
    }
}
